import axios from 'axios'
import qs from 'qs'

const request = (url = '', params = {}, type = 'POST') => {
	const serverHost = window.host;
	let urlParams = qs.stringify(params);
	
	return new Promise((resolve, reject) => {
		if(type == 'GET') {
			url = `${serverHost}${url}?${urlParams}`;
			axios.get(url).then((res) => {
				resolve(res.data)
			}).catch((err) => {
				reject(err)
			})
		}
		if(type == 'POST') {
			 url = `${serverHost}${url}`;
			axios.post(url, params).then((res) => {
				resolve(res.data)
			}).catch((err) => {
				reject(err)
			})
		}
	})
}

/*
    测试接口
 */
const API = {
	feedback : (param) => request('/user/Feedback', param)
}

export default API
